package org.aaron.wbclient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import oauth.signpost.OAuth;

import org.aaron.wbclient.model.WeiBoHomeList;
import org.aaron.wbclient.oauth.Constans;
import org.aaron.wbclient.oauth.PrepareRequestActivity;

import com.google.gson.Gson;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.gsm.GsmCellLocation;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TencentWeiBoClientActivity extends Activity {

	private Button requestBtn;
	private Button addWeiBoBtn, getHomeTimeLineWeiBoBtn;
	private SharedPreferences preferences;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initActivity();
	}

	private void initActivity() {
		requestBtn = (Button) findViewById(R.id.requestBtn);
		requestBtn.setOnClickListener(new requestBtnClickListener());

		addWeiBoBtn = (Button) findViewById(R.id.addWeiBoBtn);
		addWeiBoBtn.setOnClickListener(new addWeiBoBtnClickListener());

		getHomeTimeLineWeiBoBtn = (Button) findViewById(R.id.getHomeTimeLineWeiBoBtn);
		getHomeTimeLineWeiBoBtn.setOnClickListener(new GetHomeTimeLineWeiBoBtnClickListener());

		preferences = PreferenceManager.getDefaultSharedPreferences(this);
	}

	class requestBtnClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			startActivity(new Intent(v.getContext(), PrepareRequestActivity.class));
		}
	}

	class addWeiBoBtnClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			WeiboClientOperate weiboClientOperate = new WeiboClientOperate(Constans.CONSUMER_KEY, Constans.CONSUMER_SECRET, preferences.getString(OAuth.OAUTH_TOKEN, ""), preferences.getString(
					OAuth.OAUTH_TOKEN_SECRET, ""));
			Map<String, String> additionalParams = new HashMap<String, String>();
			additionalParams.put("format", "json");
			additionalParams.put("content", "test");
			additionalParams.put("clientip", "127.0.0.1");

			List<String> decodeParams = new ArrayList<String>();
			decodeParams.add("oauth_signature");
			weiboClientOperate.doPost(Constans.TENTENT_WEIBO_API.TENCENTWEIBO_ADD_URL, additionalParams, decodeParams);

		}
	}

	class GetHomeTimeLineWeiBoBtnClickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			startActivity(new Intent(TencentWeiBoClientActivity.this, HomeTimeLineActivity.class));
		}
	}
}